from rest_framework import serializers

from recruits.models import City, Recruit, Enterprise


class CitySerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = '__all__'


class EnterpriseSerializer(serializers.ModelSerializer):
    class Meta:
        model = Enterprise
        fields = ('id', 'name', 'labels', 'logo', 'recruits', 'summary')


class JobSerializer(serializers.ModelSerializer):
    enterprise = EnterpriseSerializer(label='企业序列化器类')

    class Meta:
        model = Recruit
        exclude = ('address', 'state', 'detailcontent', 'detailrequire', 'visits', 'users')


class RecruitsDetailSerializer(serializers.ModelSerializer):
    users = serializers.StringRelatedField()
    enterprise = EnterpriseSerializer()

    class Meta:
        model = Recruit
        exclude = ('address', 'state', 'detailrequire', 'detailcontent')


class EnterpriseDetailSerializer(serializers.ModelSerializer):
    recruits = RecruitsDetailSerializer(many=True)
    users = serializers.StringRelatedField()

    class Meta:
        model = Enterprise
        fields = '__all__'


class JobDetailSerializer(serializers.ModelSerializer):
    enterprise = EnterpriseDetailSerializer()
    users = serializers.StringRelatedField()

    class Meta:
        model = Recruit
        fields = '__all__'


class EnterpriseDetailedSerializer(serializers.ModelSerializer):
    recruits = JobSerializer(many=True)

    class Meta:
        model = Enterprise
        fields = '__all__'
